﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CRMFramework;
using System.Globalization;

namespace CRMEntity
{
    public class Assesment
    {
        public int AssesmentID { get; set; }
        public int app_id { get; set; }
        public string assesLastResult { get; set; }
        public string assesLastDate { get; set; }
        public string accountNo { get; set; }
        public string lender { get; set; }
        public string note { get; set; }
        public string hoperator { get; set; }
        public string CreatedDate { get; set; }
        public string EditDate { get; set; }

        public Assesment() { }

        public DataSet GetAssesmentDataByAppID(int app_id)
        {
            DataSet ds;

            try
            {
                var para = new[]{
                    DBhelper.SetParameter("@p_app_id",app_id)
                };
                ds = DBhelper.ExecuteDataset("Select * FROM crm_assesment where app_id=@p_app_id limit 1", para);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;
        }

        public int SaveAssesmentData()
        {
            try
            {
                var para = new[]{
                    DBhelper.SetParameter("@p_AssesmentID",AssesmentID),
                    DBhelper.SetParameter("@p_app_id",app_id),
                    DBhelper.SetParameter("@p_asseslastresult",assesLastResult),
                    DBhelper.SetParameter("@p_asseslastdate",assesLastDate),
                    DBhelper.SetParameter("@p_accountno",accountNo),
                    DBhelper.SetParameter("@p_lender",lender),

                    DBhelper.SetParameter("@p_note",note),
                    DBhelper.SetParameter("@p_operator",hoperator),
                };

                DBhelper.ExecuteNonQuerySP("sp_saveAssesmentData", para);

                if (AssesmentID == 0)
                   return int.Parse(DBhelper.ExecuteScalar("Select MAX(AssesmentID) from crm_assesment"));
                else
                   return   AssesmentID;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
